package com.lagou.dao;

import com.lagou.entity.Phone;
import com.lagou.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class PhoneDao {

    QueryRunner qr = new QueryRunner(DruidUtils.GetDataSource());
    /**
     *  查询价格高于2000元，生产日期是2019年之前的所有手机
     */
    public List<Phone> findPhone(String price,String time) throws SQLException {
        String sql = "select * from phone where price > ? and prodate < ?";
        List<Phone> list = qr.query(sql, new BeanListHandler<Phone>(Phone.class), price, time);
        return list;
    }
    /**
     * 查询所有颜色是白色的手机信息
     */
    public Phone findPhoneByColor(String color) throws SQLException {
        String sql = "select * from phone where color = ?";
        Phone query = qr.query(sql, new BeanHandler<Phone>(Phone.class), color);
        return query;
    }
}
